﻿using System;
using System.Globalization;
using Google.Analytics.Model.Queries;
using Google.Analytics.Web.Converters;
using NUnit.Framework;

namespace Google.Analytics.WebTests
{
    public class EnumConverterTests : ConverterTestBase<EnumConverter<Metrics>, Metrics>
    {
        [Test]
        public void ConvertFromSingle()
        {
            var expected = new[] { Metrics.Visits };
            var result = Converter.ConvertFrom(GetTypeContext(), CultureInfo.CurrentCulture, "Visits");
            VerifyConverFromResult(result, expected);
        }

        [Test]
        public void ConvertFromMultiple()
        {
            var expected = new[] { Metrics.Visits, Metrics.TotalEvents };
            var result = Converter.ConvertFrom(GetTypeContext(), CultureInfo.CurrentCulture, "Visits,TotalEvents");
            VerifyConverFromResult(result, expected);
        }

        [Test]
        public void ConvertFromMultipleSpace()
        {
            var expected = new[] { Metrics.Visits, Metrics.TotalEvents };
            var result = Converter.ConvertFrom(GetTypeContext(), CultureInfo.CurrentCulture, "Visits, TotalEvents");
            VerifyConverFromResult(result, expected);
        }

        [Test]
        public void ConvertFromMultipleExtraComma()
        {
            var expected = new[] { Metrics.Visitors, Metrics.TimeOnPage };
            var result = Converter.ConvertFrom(GetTypeContext(), CultureInfo.CurrentCulture, "Visitors,TimeOnPage,");
            VerifyConverFromResult(result, expected);
        }

        [Test]
        public void ConvertFromEmpty()
        {
            var expected = new Metrics[] { };
            var result = Converter.ConvertFrom(GetTypeContext(), CultureInfo.CurrentCulture, "");
            VerifyConverFromResult(result, expected);
        }

        [Test]
        public void ConvertFromSingleComma()
        {
            var expected = new Metrics[] { };
            var result = Converter.ConvertFrom(GetTypeContext(), CultureInfo.CurrentCulture, ",");
            VerifyConverFromResult(result, expected);
        }

        [Test]
        public void ConvertToSingle()
        {
            var actual = new[] { Metrics.NewVisits };
            var result = Converter.ConvertTo(GetTypeContext(), CultureInfo.CurrentCulture, actual, typeof(string));
            VerifyCovnertToResult(result, "NewVisits");
        }

        [Test]
        public void ConvertToMultiple()
        {
            var actual = new[] { Metrics.TimeOnSite, Metrics.Visitors };
            var result = Converter.ConvertTo(GetTypeContext(), CultureInfo.CurrentCulture, actual, typeof(string));
            VerifyCovnertToResult(result, "TimeOnSite,Visitors");
        }
    }
}
